from pydantic import BaseModel
from datetime import datetime
from typing import Optional, List


class HiDolphinQaDataCreate(BaseModel):
    id: str
    user_id: str
    project_id: str
    query: str
    answer: str
    input_tokens: int
    output_token: int
    total_token: int
    timestamp: datetime
    resolved: int

    model_config = {'from_attributes': True}


class HiDolphinQaDataWDTO(BaseModel):
    id: str
    user_id: str
    project_id: str
    timestamp: Optional[datetime] = None
    tags: Optional[List[str]] = None  # 改为 list 类型
    bookmarked: bool
    name: Optional[str] = None
    release: Optional[str] = None
    version: Optional[str] = None
    session_id: Optional[str] = None
    public: bool
    input: Optional[str] = None
    output: Optional[str] = None
    metadata: Optional[str] = None
    latency: float
    usage: Optional[str] = None
    input_cost: Optional[float] = 0.0  # 允许为 0
    output_cost: Optional[float] = 0.0
    total_cost: Optional[float] = 0.0
    level: Optional[str] = None
    error_count: int = 0
    warning_count: int = 0
    debug_count: int = 0
    observation_count: int = 0
    input_tokens: int = 0
    output_tokens: int = 0
    total_tokens: int = 0
    default_count: Optional[int] = 0


class VvvUserLoginLogCreate(BaseModel):
    id: str
    company_type: Optional[str] = None
    user_id: Optional[str] = None
    register_channel: Optional[str] = None
    register_time: Optional[datetime] = None
    channel_client: Optional[str] = None
    login_type: Optional[str] = None
    login_time: Optional[datetime] = None
    resolved: Optional[int] = 0

    model_config = {'from_attributes': True}


class VvvApiCallRecordCreate(BaseModel):
    id: str
    company_type: Optional[str] = None
    user_id: Optional[str] = None
    access_date: Optional[datetime] = None
    access_times: Optional[int] = 0
    api_name: Optional[str] = None
    resolved: Optional[int] = 0

    model_config = {'from_attributes': True}


# label_schemas.py

# LabelCreate: 用于创建标签
class LabelCreate(BaseModel):
    id: Optional[str] = None
    label_code: Optional[str] = None
    label_name: Optional[str] = None
    label_desc: Optional[str] = None
    parent_label_id: Optional[str] = None
    label_type: Optional[str] = None
    label_key: Optional[str] = None

    model_config = {'from_attributes': True}


# LabelRDTO: 用于返回
class LabelRDTO(BaseModel):
    id: Optional[str] = None
    label_code: Optional[str] = None
    label_name: Optional[str] = None
    label_desc: Optional[str] = None
    parent_label_id: Optional[str] = None
    label_type: Optional[str] = None
    label_key: Optional[str] = None

    model_config = {'from_attributes': True}


# LabelUserCreate: 用于创建标签用户关联记录
class LabelUserCreate(BaseModel):
    id: Optional[str] = None
    label_id: Optional[str] = None
    user_id: Optional[str] = None
    label_value: Optional[int] = 0

    model_config = {'from_attributes': True}


# LabelUserRDTO: 用于返回
class LabelUserRDTO(BaseModel):
    id: Optional[str] = None
    label_id: Optional[str] = None
    user_id: Optional[str] = None
    label_value: Optional[int] = 0

    model_config = {'from_attributes': True}


# UserRDTO: 用于返回
class UserRDTO(BaseModel):
    id: Optional[str] = None
    user_name_cn: Optional[str] = None
    company_id: Optional[str] = None
    company_type: Optional[str] = None
    user_id: Optional[str] = True
    liveness: Optional[str] = False

    model_config = {'from_attributes': True}
